<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class CnDiagnose extends Model
{
    public $timestamps = false;

    protected $table = 'st_cn_diagnoses';

    protected $fillable = [
        'record_id', 'cn_disease_id', 'type_id', 'carry_key'
    ];

    public function disease()
    {
        return $this->belongsTo(CnDiseaseDictionary::class, 'cn_disease_id')
                    ->select(['id', 'name', 'icd']);
    }

    public function setCarryKeyAttribute($value)
    {
        if (is_array($value)) {
            $value = implode(',', $value);
        }

        $this->attributes['carry_key'] = $value;
    }

    public function getCarryKeyAttribute($value)
    {

        return $value ? explode(',', $value) : [];
    }
}
